package ooday04;

public class Test {
    public static void main(String[] args) {
/*
        Dog[] dogs=new Dog[3];
        dogs[0]=new Dog("小黑",2,"白");
        dogs[1]=new Dog("旺财",4,"黄");
        dogs[2]=new Dog("二哈",1,"黑白相间");
        for(int i=0;i<dogs.length;i++){
            System.out.println(dogs[i].name);
            dogs[i].eat();
            dogs[i].drink();
        }

        Chick[] chicks=new Chick[2];
        chicks[0]=new Chick("坤坤",2,"黑衣白带");
        chicks[1]=new Chick("胸大鸡",10,"黄");
        for(int i=0;i<chicks.length;i++){
            System.out.println(chicks[i].name);
            dogs[i].eat();
            dogs[i].drink();
        }

        Fish[] fish=new Fish[4];
        fish[0]=new Fish("俞俐均",22,"白");
        fish[1]=new Fish("大白鲨",4,"白");
        fish[2]=new Fish("美人鱼",1,"粉");
        fish[3]=new Fish("幸运鲤",1,"红");
        fish[2].age=2;
        for(int i=0;i<fish.length;i++){
            System.out.println(fish[i].name);
            dogs[i].eat();
            dogs[i].drink();
        }

 */

        Animal[] animals=new Animal[3];
        animals[0]=new Dog("旺财",4,"黄");//向上造型
        animals[1]=new Chick("坤坤",2,"黑白");
        animals[2]=new Fish("锦鲤",1,"红");
        for(int i=0;i<animals.length;i++){
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();
            if(animals[i] instanceof Dog){//用instanceof来判断，避免发生类型转换异常
                Dog dog=(Dog)animals[i];
                dog.lookHome();
                dog.swim();
            }
            if(animals[i] instanceof Chick){
                Chick chick=(Chick)animals[i];
                chick.layEggs();
            }
            if(animals[i] instanceof Fish){
                Fish fish=(Fish)animals[i];
                fish.swim();
            }
        }


/*

        Master master=new Master();
        Dog dog=new Dog("uzi",1,"黄");
        Chick chick=new Chick("坤坤",2,"黑白");
        Fish fish=new Fish("大白鲨",3,"白");
        master.feed(dog);//,参数类型是Animal，在传参时自动向上造型
        master.feed(chick);
        master.feed(fish);

 */

    }


}
